﻿using UnityEngine;
using UnityEngine.Events;
using System.Collections;
using System;
using System.Text;

public static class Util {

    public static void CallUnityAction (UnityAction action) {
        if (null != action) {
            action( );
        } else {
            Debuger.LogError("UnityAction is null");
        }
    }

    public static void CallAction (Action action) {
        if (null != action) {
            action( );
        } else {
            Debuger.LogError("Action is null");
        }
    }

    public static void CallAction<T> (Action<T> action, T obj) {
        if (null != action) {
            action(obj);
        } else {
            Debuger.LogError("Action<T> is null");
        }
    }

    public static void CallAction<T1, T2> (Action<T1, T2> action, T1 obj1, T2 obj2) {
        if (null != action) {
            action(obj1, obj2);
        } else {
            Debuger.LogError("Action<T1, T2> is null");
        }
    }

    public static GameObject CreateView (string viewName) {
        // Loads the prefab with the view and instantiates it inside the View hierarchy
        GameObject view = GameObject.Find(viewName);
        if (null != view) {
            return view;
        } else {
            Debuger.LogError(string.Format("viewName GameObject: {0} can't find in scene: {1}", viewName, Application.loadedLevelName));
        }

        return null;
    }

    public static void ClearStringBuilder (StringBuilder sb) {
        if (null != sb) {
            sb.Remove(0, sb.Length);
        } else {
            Debuger.LogError(string.Format("StringBuilder is null"));
        }
    }

}
